using DesignerHelper.Main;
using SpreadsheetGear;

namespace DesignerHelper.Addons.TemplateConvertor
{
    public class HwrxConvertor : FileConvertor
    {
        protected sealed override IWorkbook WorkOn { get; }
        //protected sealed override LockBookWorker LbwTrigger { get; set; }
        protected sealed override IWorkbook NewCtpx { get; }

        public override void BeginConvert()
        {
            IWorksheet hardwareLibrary = NewCtpx.Worksheets[3];
            IRange machineTokens = hardwareLibrary.Range["J1"];
            CopyTo(WorkOn.Worksheets["HardwareLibrary"], hardwareLibrary.Range, true);
            CopyTo(WorkOn.Worksheets["MachineTokens"], machineTokens, false);

            string str = GetRangeAddress(WorkOn.Names["MFHW"].RefersToRange);
            NewCtpx.Names.Add("MFHW", '=' + hardwareLibrary.Name + '!' + str);
        }

        public HwrxConvertor(IWorkbook workOn, IWorkbook ctpxNew)
        {
            WorkOn = workOn;
            NewCtpx = ctpxNew;
            //LbwTrigger = LockBookWorker.GetWorker(WorkOn);
        }
        protected sealed override void CopyTo(IWorksheet source, IRange target, bool renameTargetWorksheet)
        {
            base.CopyTo(source, target, renameTargetWorksheet);
            AutoFit(target["$A:$A"].Columns, target["$E:$E"].Columns, target["$B:$B"].Columns);
        }
    }
}